-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set info logging level in find_tailcuts #1349
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1349 +/- ##
==========================================
- Coverage 72.86% 72.86% -0.01%
==========================================
Files 137 137
Lines 14515 14516 +1
==========================================
Hits 10577 10577
- Misses 3938 3939 +1 ☔ View full report in Codecov by Sentry. |
In principle not, I think it should be controlled by the level set in the main script calling the other module (see example at the top of https://docs.python.org/3/library/logging.html). Maybe need to set explicitly the level for file handler as well. In def main():
args = parser.parse_args()
output_dir = args.output_dir.absolute()
output_dir.mkdir(exist_ok=True, parents=True)
log.setLevel(logging.INFO)
# Console handler
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(console_handler)
# File handler
log_file = args.log_file or f'log_find_tailcuts_Run{run_id:05d}.log'
log_file = output_dir / log_file
file_handler = logging.FileHandler(log_file, mode='w')
file_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(file_handler)
... |
I will try, thanks a lot for the info! |
Adding the console handler resulted in duplication of the (incomplete) output in stdout. |
@morcuended I tried to follow the suggestions in the link you sent and did not help. The only way I seem to be able to activate INFO logging is inside cleaning.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know the reason why. It is still strange to me that it is not controlled by the main script calling the function.
Therefore, use the definition inside the function for the time being.
I think you need to specify which module you are specifying the log level for. For exemple this is how I set up the logging level for BaccMod in a notebook :
The name used can be on a of any scope (package, module). logging.getLogger('lstchain.image.cleaning').setLevel(logging.INFO) |
Thanks, that's it indeed. I will do it like that. |
Good! For me, it is still a mystery that you cannot control the level with the root logger, without having to specify explicitly the submodule, but for all lstchain modules at the same time. Maybe I'm misunderstanding something from the logging system. @moralejo, are the rest of INFO messages from other parts of the code shown as well? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better this way than defining it inside the function.
You can set the level for all lstchain in one go with Current implementation will show the INFO messages of the script itself (level defined in line 51) and of methods in lstchain.image.cleaning' but not from elsewhere. |
I think I see now my wrong understanding. log = logging.getLogger(__name__)
def main():
args = parser.parse_args()
log.setLevel(logging.INFO)
Keep in mind that no other INFO message (default is WARNING) will appear outside |
I got the same output as when I defined the level inside the function |
Yes, but this is what I want here. |
Ok, thanks! Not a problem in this case. |
Not sure if there is a better way to set it (let me know if that is the case). Doing it in the script which calls the function did not work.